/**
 * 
 */
package com.fruit.app.common.util;

import java.util.Random;

/**
 * @Discription: 密码工具类
 * @ClassName: GeneratedPasswords
 *
 * @Author:[caiwei]
 * @Version 1.0
 * @Date 2012-4-23 下午3:21:58
 *
 */
public abstract class Passwords {

	private static StringBuffer bufferSecretRange=new StringBuffer("23456789abcdefghijkmnpqrstuvwxyz");
	
	/**
	 * @Title: GeneratedPasswords
	 * @Discription: 生成指定位数的用户密码(0-9,a-z)
	 *
	 * @Author:[caiwei]
	 * @Version 1.0
	 * @Date 2012-4-23 下午3:37:05
	 *
	 * @param length
	 * @return
	 * @ReturnType: String
	 */
	public static String GeneratedPasswords(Integer length) {
		Random random = new Random();
		StringBuffer stringCache = new StringBuffer();
		for (int i = 0; i < length; i++) {
			stringCache.append(bufferSecretRange.charAt(random.nextInt(bufferSecretRange.length())));
		}
		return stringCache.toString();
	}
	
	/**
	 * @Title: GeneratedBase64EncryptedPasswords
	 * @Discription: 生成指定位数的用户密码(0-9,a-z)并用户Base64加密算法加密
	 *
	 * @Author:[caiwei]
	 * @Version 1.0
	 * @Date 2012-4-23 下午3:37:07
	 *
	 * @param length
	 * @return
	 * @ReturnType: String
	 */
	public static String GeneratedBase64EncryptedPasswords(Integer length){
		return Base64.encodeBase64(GeneratedPasswords(length));
	}
}
